<%@page import="com.net.domain.StudentAttendanceDetail"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="com.net.domain.UserType,com.net.domain.AttendanceStatus,com.net.domain.StudentAttendanceDetail,java.util.List" %>

<form method="POST" name="student" action="/MamNet/attendance/writeAttendance">
<input type="hidden" name="randomkey" value="${randomkey }" />
<input type="hidden" name="class_hour" value="${class_hour }" />
<input type="hidden" name="date" value="${date }" />
<table border="1">

<%
	// generate the radio buttons based on the entry in the database for this date
	
	List<StudentAttendanceDetail> studentList = (List<StudentAttendanceDetail>)request.getAttribute("students");
			
	for(StudentAttendanceDetail student : studentList) {
		
		out.println("<tr><td>" + student.getStudent().getFirstName()+ "</td><td>" +student.getStudent().getRegisterNo() + "</td>");
		
		if(student.getStatus() != null) {
			out.print("<td><input type=\"radio\" name=\"status_"+ student.getStudentId() +"\" value=\"");
			out.println(AttendanceStatus.PRESENT.getValue() + 
					"\"" + (student.getStatus().equalsIgnoreCase(AttendanceStatus.PRESENT.getValue()) ? " checked" : "")  + 
					"> " + AttendanceStatus.PRESENT.toString() + "</td>");
			out.println("<td><input type=\"radio\" name=\"status_" + student.getStudentId() + 
					"\" value=\"" + AttendanceStatus.ABSENT.getValue() + "\"" +
					(student.getStatus().equalsIgnoreCase(AttendanceStatus.ABSENT.getValue()) ? " checked" : "") +
					">" + AttendanceStatus.ABSENT.toString() + "</td>");
			out.println("<td><input type=\"radio\" name=\"status_" + student.getStudentId() +
					"\" value=\"" + AttendanceStatus.ONDUTY.getValue() + "\"" +
					(student.getStatus().equalsIgnoreCase(AttendanceStatus.ONDUTY.getValue()) ? " checked" : "") +
					">" + AttendanceStatus.ONDUTY.toString() + "</td>");
		}
		else {			
			out.print("<td><input type=\"radio\" name=\"status_"+ student.getStudentId() +"\" value=\"");
			out.println(AttendanceStatus.PRESENT.getValue() + "\" checked > " + AttendanceStatus.PRESENT.toString() + "</td>");
			out.println("<td><input type=\"radio\" name=\"status_" + student.getStudentId() + "\" value=\"" + AttendanceStatus.ABSENT.getValue() + "\">" + AttendanceStatus.ABSENT.toString() + "</td>");
			out.println("<td><input type=\"radio\" name=\"status_" + student.getStudentId() + "\" value=\"" + AttendanceStatus.ONDUTY.getValue() + "\">" + AttendanceStatus.ONDUTY.toString() + "</td>");	
		}
		
		out.println("</tr>");
	}
			
%>

<%-- 	<c:forEach items="${students}" var="studentAttendance">
		<tr><td>${studentAttendance.student.firstName}</td>
		<td><input type="radio" name="status_${studentAttendance.studentId }" value="<% out.print(AttendanceStatus.PRESENT.getValue()); %>" checked><% out.print(AttendanceStatus.PRESENT.toString()); %></td>
		<td><input type="radio" name="status_${studentAttendance.studentId }" value="<% out.print(AttendanceStatus.ABSENT.getValue()); %>" ><% out.print(AttendanceStatus.ABSENT.toString()); %></td>
		<td><input type="radio" name="status_${studentAttendance.studentId }" value="<% out.print(AttendanceStatus.ONDUTY.getValue()); %>" ><% out.print(AttendanceStatus.ONDUTY.toString()); %></td>
		</tr>
	</c:forEach>
 --%>
</table>

	<input type="submit" value="Dislay Student" />
	
</form>